package com.lsf.dunlian.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lsf.dunlian.R;
import com.lsf.dunlian.callback.ListClickCallback;
import com.lsf.dunlian.entity.MemberDetailProgressEntity;
import com.lsf.dunlian.entity.MemberListTitleEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MemberDetailProgressRecyclerViewAdapter extends RecyclerView.Adapter<MemberDetailProgressRecyclerViewAdapter.ViewHolder> {
    private List<MemberDetailProgressEntity> mDataList;
    private Context context;

    private ListClickCallback clickCallback;

    public MemberDetailProgressRecyclerViewAdapter(List<MemberDetailProgressEntity> mDataList, Context context) {
        this.mDataList = mDataList;
        this.context = context;
    }

    public void setClickCallback(ListClickCallback clickCallback) {
        this.clickCallback = clickCallback;
    }

    @NonNull
    @Override
    public MemberDetailProgressRecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_progress, parent, false);
        MemberDetailProgressRecyclerViewAdapter.ViewHolder holder = new MemberDetailProgressRecyclerViewAdapter.ViewHolder(view);
        return holder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        MemberDetailProgressEntity recordData = mDataList.get(position);
        holder.name.setText(recordData.title);
        if (recordData.select){
            holder.name.setTextColor(context.getResources().getColor(R.color.zhuti));
            holder.img.setBackgroundResource(R.drawable.jiantou_red);
        }else {
            holder.name.setTextColor(context.getResources().getColor(R.color.black));
            holder.img.setBackgroundResource(R.drawable.jiantou_gray);
        }
        if (position == mDataList.size()-1) {
            holder.img.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.img)
        ImageView img;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
